@extends('backstage.layout.master')
@section('title', '产品模板列表')
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a target="_blank" href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a target="_blank" href="/backstage/product-temp/product-temp-list">产品模板</a>
            </li>
            <li>
                产品模板列表
            </li>
        </ul><!-- .breadcrumb -->

        <div class="nav-search" id="nav-search">
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                产品模板
                <small>
                    <i class="icon-double-angle-right"></i>
                    产品模板列表
                </small>
                <span class="pull-right">
                    <button class="btn btn-primary" onclick="javascript:window.location.href='{{asset('')}}backstage/product-temp/add-product-temp';">添加产品模板</button>
                </span>
            </h1>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="well">
                    <form action="javascript:void(0)" name="searchForm">
                        <img src="images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH">
                        <!-- 品牌 -->
                        品牌:<select name="brand_id" id="brand_id">
                            <option value=0>全部</option>
                            @foreach($brands as $brand)
                                <option @if($brand_id===$brand->brand_id) selected @endif value={{isset($brand->brand_id)?$brand->brand_id:0}}>
                                    {{isset($brand->brand_name)?$brand->brand_name:''}}</option>
                            @endforeach
                        </select>
                        产品模板类型:<select name="category_id" id="category_id">
                            <option value=0>全部</option>
                            @foreach($temp_categorys as $temp_category)
                                <option @if($temp_category_id===$temp_category->id) selected @endif value={{isset($temp_category->id)?$temp_category->id:0}}>{{isset($temp_category->name)?$temp_category->name:''}}</option>
                            @endforeach
                        </select>
                        <!-- 关键字 -->
                        <input type="button" id="filter_btn" value=" 搜索 " class="button">
                    </form>
                </div>
            </div>
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </th>
                            <th>产品Id</th>
                            <th>产品名称</th>
                            <th>产品类型</th>
                            <th>品牌</th>
                            <th>更新时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach ($product_temps as $product_temp)
                        <tr class="" data-tr-id="{{isset($product_temp->product_temp_id)?$product_temp->product_temp_id:'0'}}">
                            <td class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </td>
                            <td>
                                {{isset($product_temp->product_temp_id)?$product_temp->product_temp_id:''}}
                            </td>
                            <td>
                                {{isset($product_temp->name)?$product_temp->name:''}}
                            </td>
                            <td>
                                {{isset($product_temp->category_name)?$product_temp->category_name:''}}
                            </td>
                            <td>
                                {{isset($product_temp->brand_name)?$product_temp->brand_name:''}}
                            </td>
                            <td>
                                {{isset($product_temp->updated_at)?date('Y-m-d H:i:s',$product_temp->updated_at):''}}
                            </td>
                            <td>
                                <ul class="nav-pills" style="list-style-type:none">
                                    <li class="dropdown all-camera-dropdown">
                                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                            <span >操作</span>
                                            <b class="caret"></b></a><ul class="dropdown-menu">
                                            <li data-filter-camera-type="Zed">
                                                <a target="_blank" href="/backstage/product-temp/update-product-temp?id={{isset($product_temp->product_temp_id)?$product_temp->product_temp_id:''}}">
                                                    <span id="">编辑</span>
                                                </a>
                                            </li>
                                            <li data-filter-camera-type="all">
                                                <a target="_blank"  href="/backstage/product-temp/add-stock?id={{isset($product_temp->product_temp_id)?$product_temp->product_temp_id:''}}">
                                                    <span >库存列表</span>
                                                </a>
                                            </li>
                                            <li data-filter-camera-type="all">
                                                <a target="_blank"  href="/backstage/product-temp/product-temp-size-list?id={{isset($product_temp->product_temp_id)?$product_temp->product_temp_id:''}}">
                                                    <span >尺码列表</span>
                                                </a>
                                            </li>
                                            <li data-filter-camera-type="all">
                                                <a  data-delete="{{isset($product_temp->product_temp_id)?$product_temp->product_temp_id:'0'}}">
                                                    <span >删除</span>
                                                </a>
                                            </li>
                                        </ul>
                                    </li>
                                </ul>
                            </td>
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $product_temps->render(); ?>
                        </div>
                    </div>
                </div>
                <!-- PAGE CONTENT ENDS -->
                <div class="row">
                    <div class="col-xs-12" style="position: static;height: 50px;">
                        <span class="input-icon">
					   <select id="selActionType"  style="width:209px;">
                            <option value =0>请选择 。。。。</option>
					   </select>
				     </span>
                        <span class="input-icon" >
                            <select id="selAction"  style="width:209px;">
					        </select>
				        </span>
                        <span class="input-icon">
                        <input  type="button" value="确定" class="btn batch_processing_submit"  style="color:#0a03ff;">
                        </span>
                    </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        $(function () {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $('[data-rel=tooltip]').tooltip();
            $('[data-delete]').click(function(){
                var  id = $(this).attr("data-delete");
                if(id!==0){
                    swal({
                        title: "确定删除？？",
                        text: "",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        closeOnConfirm: true,
                        closeOnCancel: true
                    },function (){
                        $.ajax({
                            type: "POST",
                            url: "/backstage/product-temp/del-product-temp",
                            data: {'id':id},
                            success: function (msg) {
                                if(msg.state==1){
                                    swal({title: "删除成功！", text: "",type: "success", timer:1000 });
                                    $('[data-tr-id='+id+']').remove();
                                }else {
                                    swal({title: msg.message, text: "",type: "error", timer:1000 });
                                }

                            }, error: function () {
                                swal({title: "系统繁忙！", text: "",type: "error", timer:1000 });
                            }
                        });
                    });
                }
            });
            $('table th input:checkbox').on('click' , function(){
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                        .each(function(){
                            this.checked = that.checked;
                            $(this).closest('tr').toggleClass('selected');
                        });

            });
            $('#selActionType').change(function() {
                var sel_action_type=parseInt($(this).val());
                switch (sel_action_type)
                {
                    case 1:
                        getResourceTags();
                        break;
                    default:
                        return false;
                        break;
                }
                return true;
            });
            $('.batch_processing_submit').click(function() {
                var data = new Array();
                var i=0;
                var sel_action_type=$('#selActionType option:selected').val();
                var sel_action=$('#selAction option:selected').val();
                sel_action_type=parseInt(sel_action_type);
                $('table th input:checkbox').closest('table').find('tr > td:first-child input:checkbox')
                        .each(function(){
                            var is_checked=$(this).is(":checked");
                            if(is_checked==true&&(tag_id!=0)){
                                var tag_id=$(this).closest('tr').attr("data-tr-id");
                                data.push(tag_id);
                            }
                        });
                if((sel_action_type==1)&&(data.length>0) ){
                    $.ajax({
                        type: "POST",
                        url: "/backstage/product-temp/batch-update-product-temp",
                        data: {'type':sel_action_type,'type_value':sel_action,'data':data},
                        success: function (msg) {
                            if(msg.state=1){
                                swal({title: '修改成功', text: "",type: "success", timer:1000 });
                                location.reload();
                            }else {
                                swal({title: msg.message, text: "",type: "error", timer:1000 });
                            }

                        }, error: function () {
                            swal({title: "系统繁忙！", text: "",type: "error", timer:1000 });
                        }
                    });
                }
            });
            $('#filter_btn').click(function() {
                var url_para='';
                var brand_id=parseInt($('#brand_id option:selected').val());
                var category_id=parseInt($('#category_id option:selected').val());

                window.location.href="/backstage/product-temp/product-temp-list?brand_id="+brand_id+'&category_id='+category_id;
            });
        });
        function getResourceTags() {
            $.ajax({
                type: "POST",
                url: "/backstage/product-temp/product-temp-resource-tags",
                data: {},
                success: function (msg) {
                    console.log(msg.data);
                    var html='';
                    if(msg.state=1){
                        for(var a=0;a<msg.data.length;a++) {
                            html+='<option value="' + msg['data'][a].tag_id + '">'+ msg['data'][a].tag_name +'</option><br />';
                        }
                        $('#selAction').html(html);
                    }else {
                        swal({title: msg.message, text: "",type: "error", timer:1000 });
                    }

                }, error: function () {
                    swal({title: "系统繁忙！", text: "",type: "error", timer:1000 });
                }
            });
        }
    </script>
@stop